const example = require('../services/example.js')
const {
    SuccessModel,
    ErrorModel
} = require('../model/ResModel')
const successInfo = require('../model/SucessInfo')
const ErrorInfo = require('../model/ErrorInfo')

async function get(ctx) {
    const {id } = ctx.query
    const res = await example._get({id})
    if (res) {
        ctx.body = new SuccessModel(successInfo.getSuccess, res)
    } else {
        ctx.body =  new ErrorModel(ErrorInfo.getFail)
    }
}
async function add(ctx) {
    const {id,params} = ctx.request.body
    const res = await example._add({id,params})
    if (res) {
        ctx.body = new SuccessModel(successInfo.addSuccess, res)
    } else {
        ctx.body = new ErrorModel(ErrorInfo.addFail)
    }
}
async function update(ctx) {
    const {id,params} = ctx.request.body
    const res = await example._update({id,params})
    if (res) {
        ctx.body =  new SuccessModel(successInfo.updateSuccess)
    } else {
        ctx.body =  new ErrorModel(ErrorInfo.updateFail)
    }
}
async function remove(ctx) {
    const {id} = ctx.request.body
    const res = await example._remove({id})
    if (res) {
        ctx.body =  new SuccessModel(successInfo.deleteSuccess)
    } else {
        ctx.body =  new ErrorModel(ErrorInfo.deleteFail)
    }
}
module.exports = {
    get,
    add,
    update,
    remove,
}
